/*
 * Copyright 2011 Angel Sanadinov
 *
 * This file is part of VBox WMI.
 *
 * VBox WMI is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * VBox WMI is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with VBox WMI.  If not, see <http://www.gnu.org/licenses/>.
 */

package Beans.Requests.MachineManagement;

import Beans.Requests.MachineManagement.Components.MediumMountSettings;
import Utilities.PermissionsConstants;

/**
 * Instances of this class are used by the user interface when a request to
 * mount a virtual medium on a virtual machine is sent to the machines management
 * service.
 *
 * @author Angel Sanadinov
 */
public class MountMediumRequest extends MachineManagementRequest
{
    private MediumMountSettings mountSettings; //the mounting settings

    /**
     * No-argument constructor. <br><br>
     * All fields are set to their invalid values.
     */
    public MountMediumRequest()
    {
        this.mountSettings = null;
        setRequestedAction(PermissionsConstants.ACTION_MACHINE_MOUNT_MEDIUM);
    }

    /**
     * Constructs a request for mounting a medium on a machine.
     *
     * @param requestorId the id of the user that made the request
     * @param serverId the id of the server on which the machine resides
     * @param machineId the id of the virtual machine
     * @param mountSettings mounting settings
     */
    public MountMediumRequest(int requestorId, int serverId, String machineId, MediumMountSettings mountSettings)
    {
        setRequestorId(requestorId);
        setServerId(serverId);
        setMachineId(machineId);
        setRequestedAction(PermissionsConstants.ACTION_MACHINE_MOUNT_MEDIUM);
        this.mountSettings = mountSettings;
    }

    /**
     * Retrieves the mounting settings.
     *
     * @return the mount settings
     */
    public MediumMountSettings getMountSettings()
    {
        return mountSettings;
    }

    /**
     * Sets the mounting settings.
     *
     * @param mountSettings the mount settings
     */
    public void setMountSettings(MediumMountSettings mountSettings)
    {
        this.mountSettings = mountSettings;
    }

    @Override
    public boolean isValid()
    {
        if(super.isValid() && mountSettings != null && mountSettings.isValid())
            return true;
        else
            return false;
    }

    /**
     * Returns a textual representation of the object. <br>
     *
     * It is in the form: "ClassName: (machineId,[controllerName,controllerPort,
     * controllerSlot,mediumId,forceMount|null])".
     *
     * @return the object represented as a String
     */
    @Override
    public String toString()
    {
        String mountConfig = null;
        if(mountSettings != null)
            mountConfig = mountSettings.getControllerName() + "," + mountSettings.getControllerPort()
                          + "," + mountSettings.getControllerSlot() + "," + mountSettings.getMediumId()
                          + "," + mountSettings.getForceMount();
        else
            ;

        return MountMediumRequest.class.getSimpleName() + ": (" + getMachineId() + "," + mountConfig + ")";
    }
}
